//
//  GreenBeanCell.m
//  LvXi_newVersion
//
//  Created by 王敏 on 16/8/26.
//  Copyright © 2016年 SJT. All rights reserved.
//

#import "GreenBeanCell.h"
@interface GreenBeanCell(){
    CGFloat _greenBeans;
}


@end

@implementation GreenBeanCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.cellHeight = 50;
        self.backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(ScreenSize.width-2*globalMargin, self.cellHeight)]];
        [self.contentView insertSubview:self.backgroundImageView atIndex:0];
        self.backgroundImageView.x = globalMargin;
        
        self.underLine = [[UIView alloc] initWithFrame:CGRectMake(2*globalMargin, self.cellHeight-1, ScreenWidth-4*globalMargin, 1)];
        self.underLine.backgroundColor = HexColor(@"#EEEEEE");
        [self.contentView addSubview:self.underLine];
        self.enableUnderLine = NO;
        
        
        self.l1 = [self creatLabelWithFont:[UIFont systemFontOfSize:17]];
        self.l1.text = @"绿豆";
        [self.contentView addSubview:self.l1];
        
        self.l2 = [self creatLabelWithFont:[UIFont systemFontOfSize:17]];
        self.l2.text = @"绿豆余额";
        [self.contentView addSubview:self.l2];
        
        self.l3 = [self creatLabelWithFont:[UIFont systemFontOfSize:18]];
        self.l3.textColor = RGBColor(58,175,45);
        
        [self.contentView addSubview:self.l3];
        
        self.l4 = [self creatLabelWithFont:[UIFont systemFontOfSize:12]];
        self.l4.text = @"个";
        self.l4.textColor = RGBColor(58,175,45);
        [self.contentView addSubview:self.l4];
        
        
        self.imgv1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"doubt_button"]];
        [self.contentView addSubview:self.imgv1];
        
        
        self.t1 = [[UITextField alloc] initWithFrame:CGRectZero];
        self.t1.userInteractionEnabled = NO;
        [self.contentView addSubview:self.t1];
        
        UIButton * selectedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        selectedBtn.size = CGSizeMake(self.cellHeight*0.5, self.cellHeight*0.5);
        [selectedBtn setImage:[UIImage imageNamed:@"selected_2_default"] forState:UIControlStateNormal];
        [selectedBtn setImage:[UIImage imageNamed:@"selected_2"] forState:UIControlStateSelected];
        [selectedBtn addTarget:self action:@selector(selectedBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        self.selectedBtn = selectedBtn;
        [self.contentView addSubview:self.selectedBtn];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.selectedBtn.x = 2*globalMargin;
    self.selectedBtn.centerY = self.cellHeight*0.5;
    self.l1.size = [self.l1.text sizeInAre:MaxSize font:self.l1.font];
    self.l1.x = self.selectedBtn.right+globalMargin*0.5;
    self.l1.centerY = self.cellHeight*0.5;
    
    self.imgv1.size = self.imgv1.image.size;
    self.imgv1.x = self.l1.right+globalMargin;
    self.imgv1.centerY = self.l1.centerY;
    
    self.l4.size = [self.l4.text sizeInAre:MaxSize font:self.l4.font];
    self.l4.x = ScreenWidth-self.l4.width - 2*globalMargin;
    self.l4.botton = self.l1.botton;
    
    self.l3.size = [self.l3.text sizeInAre:MaxSize font:self.l3.font];
    self.l3.x = self.l4.left - self.l3.width;
    self.l3.centerY = self.l1.centerY;
    
    self.l2.size = [self.l2.text sizeInAre:MaxSize font:self.l2.font];
    self.l2.x= self.l3.left - self.l2.width;
    self.l2.centerY = self.l1.centerY;
    
    self.t1.x = self.imgv1.right+globalMargin;
    self.t1.centerY = self.l1.centerY;
    self.t1.height = self.cellHeight;
    self.t1.width = self.l2.left - self.imgv1.right-globalMargin;
    
    
}
-(void)setEnableUnderline:(BOOL)enableUnderLine{
    _enableUnderLine = enableUnderLine;
    self.underLine.hidden = !_enableUnderLine;
}


-(UILabel*)creatLabelWithFont:(UIFont*)font{
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.textAlignment = NSTextAlignmentLeft;
    label.font = font;
    label.textColor = [UIColor blackColor];
    return label;
}

-(void)selectedBtnClick:(UIButton*)btn{
    if(self.handleCallBack){
        self.handleCallBack(btn);
    }
}

@end
